<template>
  <div class="error-container">
    <div class="error-content">
      <div class="error-code">
        <span class="number" v-for="(num, index) in codeNumbers" :key="index">{{
          num
        }}</span>
      </div>
      <h1 class="error-title">页面未找到</h1>
      <p class="error-message">抱歉，你访问的页面不存在或已被移除</p>
      <div class="error-actions">
        <el-button type="primary" @click="goBack">
          <el-icon><ArrowLeft /></el-icon>
          返回上一页
        </el-button>
        <el-button type="default" @click="goHome">
          <el-icon><House /></el-icon>
          回到首页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { ArrowLeft, House } from "@element-plus/icons-vue";

const router = useRouter();
const codeNumbers = ref([4, 0, 4]);

const goBack = () => {
  router.go(-1);
};

const goHome = () => {
  router.push("/");
};

onMounted(() => {
  const numbers = document.querySelectorAll(".error-code .number");
  numbers.forEach((num, index) => {
    setTimeout(() => {
      num.classList.add("animate");
    }, index * 200);
  });
});
</script>

<style scoped lang="less">
.error-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8eb 100%);
  padding: 20px;
}

.error-content {
  text-align: center;
  padding: 40px;
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  max-width: 600px;
  width: 100%;
}

.error-code {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;

  .number {
    font-size: 100px;
    font-weight: bold;
    color: #409eff;
    margin: 0 10px;
    display: inline-block;
    transform: translateY(0);
    opacity: 0;
    animation: fadeUp 0.6s forwards;

    &.animate {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

.error-title {
  font-size: 28px;
  color: #333;
  margin-bottom: 10px;
}

.error-message {
  font-size: 16px;
  color: #666;
  margin-bottom: 30px;
}

.error-actions {
  display: flex;
  justify-content: center;
  gap: 15px;

  .el-button {
    padding: 10px 25px;
    transition: all 0.3s ease;

    &:hover {
      transform: translateY(-2px);
    }
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
